package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.mappers.VoiceMapper;
import com.tanhua.model.domain.Voice;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@DubboService
public class VoiceApiImpl implements VoiceApi {
    @Autowired
    private VoiceMapper voiceMapper;

    @Override
    public Boolean findCount(Long userId) {
        List<Voice> list = voiceMapper.findCount(userId);
        if (list.size() >= 10) {
            return false;
        }
        return true;
    }

    @Override
    public void sendVoice(Voice voice) {
        voiceMapper.insert(voice);
    }

    @Override
    public List<Voice> findList(Long userId) {
        QueryWrapper<Voice> qw = new QueryWrapper<>();
       // qw.ne("receive_id",userId);
        qw.ne("like_type",1);
        qw.ne("user_id",userId);
        List<Voice> list = voiceMapper.selectList(qw);
        return list;
    }

    @Override
    public int findByUserId(Long userId) {
      List<Voice> list =  voiceMapper.findList(userId);
      return list.size();
    }

    @Override
    public void update(Voice voice) {
        voiceMapper.updateById(voice);
    }
}
